<?php
	//timer pengecekan load page...
	include("inc/timer.php");
	$_start_timer = get_microtime();

	require_once("protect1.php"); 
	require_once("inc/connect.php");
	require_once("inc/settings.php");

	//$pdo->query("USE uwika_krs");
	$_kodemk = $_POST["kodemk"];
	//pengecekan pada batal KRS cuman cek KRSnya aktif/ tidak 
	// dan Validasinya.
	
	/* cek level mahasiswa */
	$sqlstr_checking_level_blokir = "SELECT username, password, level FROM security WHERE username=:uname";
	$stmt_checking_level_blokir = $pdo->prepare($sqlstr_checking_level_blokir);
	$stmt_checking_level_blokir->execute(array(':uname' => $reg_uname));
	//because of php 5.2 $_POST['name'] = $name, that makes me difficult for working -_-
	if($row_checking_level_blokir = $stmt_checking_level_blokir->fetch(PDO::FETCH_OBJ)){
		if($row_checking_level_blokir->level != 1){
			echo 'Mohon Maaf, Account Anda untuk sementara waktu ini kami <strong>BLOKIR</strong>
				Jika anda belum menyelesaikan biaya daftar ulang / biaya denda atas keterlambatan KRS, silahkan menghubungi Biro Administrasi Keuangan.
				Terimakasih';
			exit;
		}
	}
	/* finish */
	
	if (date("Y-m-d H:i:s") >= $_global_settings['waktu_krs_mulai']->value && date("Y-m-d H:i:s") <= $_global_settings['waktu_krs_selesai']->value){ // batasan waktu (jam 30 agust 13.00.01 - 14 sept 23.59.59)
		/* Masih masa KRS-an */
		$sql = "delete from registrasi WHERE nrp = :nrp and kodemk = :kodemk and periode = :periode and sesi = :sesi";
		$stmt = $pdo->prepare($sql);
		$stmt->execute(array(':nrp' => $reg_uname
								,':kodemk' => $_kodemk
								,':periode' => $_global_settings['tahun_ajaran']->value
								,':sesi' => $_global_settings['semester']->value))
		or die("ERROR: " . implode(":", $stmt->errorInfo()));
		$host  = $_SERVER['HTTP_HOST'];
		$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
		$extra = 'view_krs.php';
		header("Location: http://$host$uri/$extra");
		?>
			<meta http-equiv="refresh" content="0; url=<?php echo $extra; ?>">
			Klik <a href="<?php echo $extra; ?>">disini</a> apabila browser anda berhenti berjalan ...
		<?php
	}
?>
